home *** CD-ROM | disk | FTP | other *** search
/ DarkBASIC - The Ultimate 3D Game Creator / PCactive 8 CD1 - DarkBasic.iso / SOFTWARE / DEMOS / DarkForge2000 / snippets_vol3 / snip_morphingstars.dba < prev    next >
Encoding:
Text File  |  2000-09-30  |  6.9 KB  |  407 lines

  1. `    ------------------------------------------------------------------------
  2. `    Morphing Stars                             DarkForge Snippet (15/9/2000)
  3. `    ------------------------------------------------------------------------
  4. `    Waveforms and bits of code taken from the Blitz Basic public beta
  5. `    just to see if it could be done. Speed is irrelevant, style is everything
  6.  
  7. sync rate 0
  8. sync on
  9. hide mouse
  10.  
  11. n=300
  12. numobjs=18
  13. d=1
  14.  
  15. `    Make our little star graphic
  16.  
  17. ink rgb(255,255,0),0 : dot 1,1
  18. ink rgb(255,100,100),0 : dot 1,0 : dot 1,2 : dot 0,1 : dot 2,1
  19. get image 1,0,0,3,3
  20.  
  21. cls 0
  22.  
  23. `    Draw a little logo
  24.  
  25. set text font "Courier"
  26. i=6
  27. for a=50 to 255 step 50
  28.     ink rgb(a,a,a),0
  29.     text i,0,"DarkForge.co.uk"
  30.     dec i
  31. next a
  32. get image 2,0,0,125,16
  33.  
  34. `    Make the bitmap
  35.  
  36. create bitmap 1,640,480
  37.  
  38. `    Set-up the arrays
  39.  
  40. dim points1(n)
  41. dim points2(n)
  42. dim points3(n)
  43. dim tpoint1(n)
  44. dim tpoint2(n)
  45. dim tpoint3(n)
  46.  
  47. object(2,n)
  48.  
  49. for t=1 to n
  50.  
  51.     tpoint1(t) = points1(t)
  52.     tpoint2(t) = points2(t)
  53.     tpoint3(t) = points3(t)
  54.  
  55. next t
  56.  
  57. curobj=2
  58.  
  59. repeat
  60.  
  61.     cls 0
  62.  
  63.     if d<250 then inc d
  64.  
  65.     if cnt>375
  66.         inc curobj
  67.         if curobj > numobjs then curobj=1
  68.         object(curobj,n)
  69.         cnt=0
  70.     endif
  71.  
  72.     for t=1 to n
  73.  
  74.         if points1(t) > tpoint1(t) then tpoint1(t) = tpoint1(t) + 1
  75.         if points1(t) < tpoint1(t) then tpoint1(t) = tpoint1(t) - 1
  76.         if points2(t) > tpoint2(t) then tpoint2(t) = tpoint2(t) + 1
  77.         if points2(t) < tpoint2(t) then tpoint2(t) = tpoint2(t) - 1
  78.         if points3(t) > tpoint3(t) then tpoint3(t) = tpoint3(t) + 1
  79.         if points3(t) < tpoint3(t) then tpoint3(t) = tpoint3(t) - 1
  80.  
  81.     next t
  82.  
  83.     inc cnt
  84.  
  85.     inc vx#,0.75
  86.     inc vy#,0.75
  87.     inc vz#,0.75
  88.  
  89.     for t=1 to n
  90.  
  91.         x3d = tpoint1(t)
  92.         y3d = tpoint2(t)
  93.         z3d = tpoint3(t)
  94.        
  95.         ty# = (y3d * cos(vx#)) - (z3d * sin(vx#))
  96.         tz# = (y3d * sin(vx#)) + (z3d * cos(vx#))
  97.         tx# = (x3d * cos(vy#)) - (tz# * sin(vy#))
  98.         tz# = (x3d * sin(vy#)) + (tz# * cos(vy#))
  99.         ox# = tx#
  100.         tx# = (tx# * cos(vz#)) - (ty# * sin(vz#))
  101.         ty# = (ox# * sin(vz#)) + (ty# * cos(vz#))
  102.  
  103.         nx = (512*tx#) / (d - tz#) + 320
  104.         ny = 240 - (512 * ty#) / (d - tz#)
  105.       
  106.         paste image 1,nx,ny
  107.  
  108.     next t
  109.  
  110.     paste image 2,0,0
  111.     copy bitmap 1,0
  112.     sync
  113.  
  114. until spacekey()=1
  115.  
  116. end
  117.  
  118. function object(object,n)
  119.  
  120.         if object=1
  121.  
  122.             for t=1 to n
  123.  
  124.                 xd# = -50
  125.                 xd# = xd# + rnd(100)
  126.                 points1(t) = xd#
  127.                 points2(t) = 0
  128.                 points3(t) = 0
  129.  
  130.             next t
  131.  
  132.         endif
  133.  
  134.         if object=2
  135.  
  136.             for t=1 to n
  137.  
  138.                 xd# = -90 + rnd(180)
  139.                 x0 = (cos(xd#) * 10) * (cos(t*360/n) * 10)
  140.                 y0 = (cos(xd#) * 10) * (sin(t*360/n) * 10)
  141.                 z0 = sin(xd#) * 100
  142.                 points1(t) = x0
  143.                 points2(t) = y0
  144.                 points3(t) = z0
  145.  
  146.             next t
  147.  
  148.         endif
  149.  
  150.         if object=3
  151.  
  152.             for t=1 to n
  153.  
  154.                 xd# = -90 + rnd(180)
  155.                 x0 = (cos(xd#)* 10) * (cos(t*360/n) * 10)
  156.                 y0 = (cos(xd#) * 10) * (sin(t*360/n) * 10)
  157.                 z0 = sin(t*360/n) * 100
  158.                 points1(t) = x0
  159.                 points2(t) = y0
  160.                 points3(t) = z0
  161.  
  162.             next t
  163.  
  164.         endif
  165.  
  166.  
  167.         if object=4
  168.  
  169.             for t=1 to n
  170.                 xd# = -90 + rnd(180)
  171.                 x0 = (cos(xd#)* 10) * (cos(xd#) * 10)
  172.                 y0 = (cos(xd#) * 10) * (sin(xd#) * 10)
  173.                 z0 = sin(xd#) * 100
  174.                 points1(t) = x0
  175.                 points2(t) = y0
  176.                 points3(t) = z0
  177.             next t
  178.  
  179.         endif
  180.  
  181.         if object=5
  182.  
  183.             for t=1 to n
  184.                 xd# = -90 + rnd(180)
  185.                 x0 = (cos(xd#)* 10) * (cos(xd#) * 10)
  186.                 y0 = (cos(xd#) * 10) * (sin(xd#) * 10)
  187.                 z0 = sin(t*360/n) * 100
  188.                 points1(t) = x0
  189.                 points2(t) = y0
  190.                 points3(t) = z0
  191.             next t
  192.  
  193.         endif
  194.  
  195.         if object=6
  196.  
  197.             for t=1 to n
  198.  
  199.                 xd# = -90 + rnd(180)
  200.                 x0 = (cos(xd#)* 10) * (cos(xd#) * 10)
  201.                 y0 = (cos(t*360/n) * 10) * (sin(xd#) * 10)
  202.                 z0 = sin(t*360/n) * 100
  203.                 points1(t) = x0
  204.                 points2(t) = y0
  205.                 points3(t) = z0
  206.  
  207.             next t
  208.  
  209.         endif
  210.  
  211.  
  212.         if object=7
  213.  
  214.             for t=1 to n
  215.  
  216.                 xd# = -90 + rnd(180)
  217.                 x0 = (cos(t*360/n)* 10) * (cos(t*360/n) * 10)
  218.                 y0 = (cos(t*360/n) * 10) * (sin(xd#) * 10)
  219.                 z0 = sin(t*360/n) * 100
  220.                 points1(t) = x0
  221.                 points2(t) = y0
  222.                 points3(t) = z0
  223.  
  224.             next t
  225.  
  226.         endif
  227.  
  228.         if object=8
  229.  
  230.             for t=1 to n
  231.  
  232.                 xd# = -90 + rnd(180)
  233.                 x0 = (cos(t*360/n)* 10) * (cos(t*360/n) * 10)
  234.                 y0 = (cos(t*360/n) * 10) * (sin(t*360/n) * 10)
  235.                 z0 = sin(t*360/n) * 100
  236.                 points1(t) = x0
  237.                 points2(t) = y0
  238.                 points3(t) = z0
  239.  
  240.             next t
  241.  
  242.         endif
  243.  
  244.         if object=9
  245.  
  246.             for t=1 to n
  247.  
  248.                 xd# = -90 + rnd(180)
  249.                 x0 = (cos(xd#)* 10) * (cos(t*360/n) * 10)
  250.                 y0 = (cos(t*360/n) * 10) * (sin(t*360/n) * 10)
  251.                 z0 = sin(xd#) * 100
  252.                 points1(t) = x0
  253.                 points2(t) = y0
  254.                 points3(t) = z0
  255.  
  256.             next t
  257.  
  258.         endif
  259.  
  260.         if object=10
  261.  
  262.             for t=1 to n
  263.  
  264.                 xd# = -90 + rnd(180)
  265.                 x0 = (cos(xd#)* 10) * (cos(t*360/n) * 10)
  266.                 y0 = (cos(t*360/n) * 10) * (sin(xd#) * 10)
  267.                 z0 = sin(xd#) * 100
  268.                 points1(t) = x0
  269.                 points2(t) = y0
  270.                 points3(t) = z0
  271.  
  272.             next t
  273.  
  274.         endif
  275.  
  276.         if object=11
  277.  
  278.             for t=1 to n
  279.  
  280.                 xd# = -90 + rnd(180)
  281.                 x0 = (cos(t*360/n)* 10) * (cos(t*360/n) * 10)
  282.                 y0 = (cos(xd#) * 10) * (sin(xd#) * 10)
  283.                 z0 = sin(t*360/n) * 100
  284.                 points1(t) = x0
  285.                 points2(t) = y0
  286.                 points3(t) = z0
  287.  
  288.             next t
  289.  
  290.         endif
  291.  
  292.         if object=12
  293.  
  294.             for t=1 to n
  295.                 xd# = -90 + rnd(180)
  296.                 x0 = (cos(xd#)* 10) * (cos(t*360/n) * 10)
  297.                 y0 = (sin(xd#) * 10) * (sin(t*360/n) * 10)
  298.                 z0 = sin(xd#) * 100
  299.                 points1(t) = x0
  300.                 points2(t) = y0
  301.                 points3(t) = z0
  302.  
  303.             next t
  304.  
  305.         endif
  306.  
  307.  
  308.         if object=13
  309.  
  310.             for t=1 to n
  311.  
  312.                 xd# = -90 + rnd(180)
  313.                 x0 = (cos(xd#)* 10) * (cos(xd#) * 10)
  314.                 y0 = (sin(xd#) * 10) * (sin(xd#) * 10)
  315.                 z0 = sin(t*360/n) * 100
  316.                 points1(t) = x0
  317.                 points2(t) = y0
  318.                 points3(t) = z0
  319.  
  320.             next t
  321.  
  322.         endif
  323.  
  324.         if object=14
  325.  
  326.             for t=1 to n
  327.  
  328.                 xd# = -90 + rnd(180)
  329.                 x0 = (cos(xd#)* 10) * (cos(xd#) * 10)
  330.                 y0 = (sin(t*360/n) * 10) * (sin(xd#) * 10)
  331.                 z0 = sin(t*360/n) * 100
  332.                 points1(t) = x0
  333.                 points2(t) = y0
  334.                 points3(t) = z0
  335.  
  336.             next t
  337.  
  338.         endif
  339.  
  340.         if object=15
  341.  
  342.             for t=1 to n
  343.  
  344.                 xd# = -90 + rnd(180)
  345.                 x0 = (sin(xd#)* 10) * (cos(xd#) * 10)
  346.                 y0 = (sin(xd#) * 10) * (sin(t*360/n) * 10)
  347.                 z0 = sin(t*360/n) * 100
  348.                 points1(t) = x0
  349.                 points2(t) = y0
  350.                 points3(t) = z0
  351.  
  352.             next t
  353.  
  354.         endif
  355.  
  356.         if object=16
  357.  
  358.             for t=1 to n
  359.  
  360.                 xd# = -90 + rnd(180)
  361.                 x0 = (cos(t*360/n)* 10) * (cos(t*360/n) * 10)
  362.                 y0 = (sin(t*360/n) * 10) * (sin(xd#) * 10)
  363.                 z0 = sin(t*360/n) * 100
  364.                 points1(t) = x0
  365.                 points2(t) = y0
  366.                 points3(t) = z0
  367.  
  368.             next t
  369.  
  370.         endif
  371.  
  372.         if object=17
  373.  
  374.             for t=1 to n
  375.  
  376.                 xd# = -90 + rnd(180)
  377.                 x0 = (cos(xd#)* 10) * (cos(t*360/n) * 10)
  378.                 y0 = (sin(t*360/n) * 10) * (sin(xd#) * 10)
  379.                 z0 = cos(xd#) * 100
  380.                 points1(t) = x0
  381.                 points2(t) = y0
  382.                 points3(t) = z0
  383.  
  384.             next t
  385.  
  386.         endif
  387.  
  388.         if object=18
  389.  
  390.             for t=1 to n
  391.  
  392.                 xd# = -90 + rnd(180)
  393.                 x0 = (cos(xd#)* 10) * (cos(xd#) * 10)
  394.                 y0 = (cos(t*360/n) * 10) * (sin(t*360/n) * 10)
  395.                 z0 = sin(t*360/n) * 100
  396.                 points1(t) = x0
  397.                 points2(t) = y0
  398.                 points3(t) = z0
  399.  
  400.             next t
  401.  
  402.         endif
  403.  
  404. endfunction
  405.  
  406.  
  407.